# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-netrc
pkgver=0.11.0
pkgrel=2
pkgdesc='Reads and writes netrc files'
arch=(any)
url='https://github.com/heroku/netrc'
license=(MIT)
depends=(ruby)
makedepends=(ruby-minitest)
options=(!emptydirs)
source=(https://github.com/heroku/netrc/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        https://github.com/heroku/netrc/commit/ea3498f9c9cadeaed7e6a155bc3c4585a17133c9.patch)
sha256sums=('1e25228e8d86f86755defe8fcbfdd647b7ac119a7fb18ea9fa36191ddb594ab4'
            'fb3b5f7495cd0f37a8f5e49824dfe004372495ec6e0b41ea1dc18314aa8310bf')

prepare() {
  cd netrc-$pkgver
  patch -p1 -i ../ea3498f9c9cadeaed7e6a155bc3c4585a17133c9.patch
  sed -e 's|git ls-files|find -type f|' -e 's|\^(changelog|\^\./(changelog|' -i netrc.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd netrc-$pkgver
  gem build netrc.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    netrc-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd netrc-$pkgver
  GEM_HOME="tmp_install/$_gemdir" ruby -e 'Dir.glob "./test/**/test_*.rb", &method(:require)'
}

package() {
  cd netrc-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.md -t "$pkgdir"/usr/share/licenses/$pkgname/
}
